package cn.sh.tools.controller;

import cn.sh.tools.service.component.lock.LockComponent;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Description 锁
 * @Classname LockController
 * @Date 2023/4/28
 * @Author sh
 **/
@Api(tags = "锁")
@RestController
@RequestMapping(value = "/lock")
public class LockController {

    @Resource
    private LockComponent lockComponent;

    @ApiOperation("JUC.lock测试")
    @RequestMapping(method = RequestMethod.POST, value = "/lockStateTest")
    public void lockStateTest(@RequestParam(value = "createThreadNum") int createThreadNum,
                              @RequestParam(value = "millis") int millis) {
        this.lockComponent.lockStateTest(createThreadNum, millis);
    }

    @ApiOperation("阻塞队列测试")
    @PostMapping(value = "/blockingTest")
    void blockingStateTest(@RequestParam(value = "capacity") int capacity,
                           @RequestParam(value = "createThreadNum") int createThreadNum) {
        this.lockComponent.blockingStateTest(capacity, createThreadNum);
    }

    @ApiOperation("死锁测试")
    @PostMapping(value = "/deadlockTest")
    void deadlockTest(@RequestParam(value = "createThreadNum") int createThreadNum) {
        this.lockComponent.deadlockTest(createThreadNum);
    }

}
